<template>
  <!-- methods: {
    
    
  }-->
  <el-container>
    <el-aside width="300px">
      <el-input placeholder="输入关键字进行过滤" v-model="filterText"></el-input>
      <el-tree
        class="filter-tree"
        :data="data"
        :props="defaultProps"
        :filter-node-method="filterNode"
        @node-click="handleNodeClick"
        ref="tree"
      ></el-tree>

      <el-button type="primary" @click="csh">初始化</el-button>
    </el-aside>
    <el-container>
      <el-main>
        <el-table
          ref="singleTable"
          :data="tableData"
          highlight-current-row
          @current-change="handleCurrentChange"
          style="width: 100%"
        >
          <el-table-column type="index" width="50"></el-table-column>
          <!-- <el-table-column property="cover" label="封面" width="300"></el-table-column> -->
          <el-table-column property="title" label="名称" width="200"></el-table-column>
          <el-table-column property="lessonNum" label="课时"></el-table-column>
          <el-table-column property="tname" label="讲师"></el-table-column>
          <el-table-column property="sname" label="专业名称"></el-table-column>
          <el-table-column property="gmtCreate" label="创建时间"></el-table-column>
          <el-table-column label="操作" width="200" align="center">
            <template slot-scope="scope">
              <router-link :to="'/stuteacher/stuedit/'+scope.row.id">
                <el-button type="primary" size="mini" icon="el-icon-edit">报名</el-button>
              </router-link>
            </template>
          </el-table-column>
        </el-table>

        <!-- 分页 -->
        <el-pagination
          :current-page="page.current"
          :page-size="page.size"
          :total="page.total"
          style="padding: 30px 0; text-align: center;"
          layout="total, prev, pager, next, jumper"
          @current-change="getlist"
        />
      </el-main>
    </el-container>
  </el-container>
</template>


<script>
import subject from "@/api/subject";
import course from "@/api/course";
export default {
  watch: {
    filterText(val) {
      this.$refs.tree.filter(val);
    }
  },
  created() {
    this.tree1();
    this.pageData();
  },
  methods: {
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    handleNodeClick(data) {
      var all = data.children;
      if (all === null || all === undefined) {
        this.cs = data.id;
        this.page.current = 1;
        this.page.list = 10;
        this.page.total = 0;
        this.pageData();
      }
    },
    csh() {
      this.cs = "";
      this.pageData();
    },
    tree1() {
      subject.getNestedTreeList().then(response => {
        if (response.success === true) {
          // console.log(response.data.subjectList);
          this.data = response.data.subjectList;
        }
      });
    },
    pageData() {
      course
        .stuPage(this.page, this.cs)
        .then(response => {
          console.log(response.data.data.records);
          this.tableData = response.data.data.records;
          this.page.current = response.data.data.current;
          this.page.list = response.data.data.list;
          this.page.total = response.data.data.total;
        })
        .catch(); //请求失败执行
    },
    handleCurrentChange() {}
  },

  data() {
    return {
      filterText: "",
      data: [],
      defaultProps: {
        children: "children",
        label: "title"
      },
      tableData: [],
      page: {
        current: 1,
        size: 10,
        total: 0
      }, //分页查询
      cs: "" // 请求参数
    };
  }
};
</script>
<style>
</style>